package com.rpframework.website.device.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.rpframework.core.BaseService;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.dao.IConvertDao;
import com.rpframework.website.device.domain.Convert;


@Service
public class IConvertService extends BaseService{
		
		public @Resource IConvertDao iDao;
	
		public Pager<Convert> getPager1(Pager<Convert> pager) {
			//long startTime = System.currentTimeMillis();
			List<Convert> list = iDao.doPager(this.packageMyBatisParam(pager));
			pager.setItemList(list);
			//pager.setCostTime(System.currentTimeMillis() - startTime);
			return pager;
		}
		
		/**
		 * 列表 
		 * @param pager
		 * @return
		 */
		public Pager<Convert> getPager(Pager<Convert> pager) {
			long startTime = System.currentTimeMillis();
			List<Convert> itemList = iDao.doPager(this.packageMyBatisParam(pager));
			pager.setItemList(itemList);
			pager.setCostTime(System.currentTimeMillis()-startTime);
			return pager;
		}
		/**
		 * 增加 或 修改方法
		 * @param t
		 * @return
		 */
		public boolean doSaveOrUpdate(Convert t) {
			if(NumberUtils.isValid(t.getId())){
				Convert db = iDao.select(t.getId());
				if(t.getUrlList() == null){
					t.setUrlList(db.getUrlList());
				}
				return iDao.update(t);
			}else{
				return iDao.insert(t);
			}
		}
}
